package cn.tedu.mm.admin.account.service.impl;


import cn.tedu.mm.admin.account.dao.persist.repository.UserRepository;
import cn.tedu.mm.admin.account.pojo.param.UserParam;
import cn.tedu.mm.admin.account.pojo.vo.UserStandardVO;
import cn.tedu.mm.admin.account.service.UserService;
import cn.tedu.mm.common.enumerator.ServiceCode;
import cn.tedu.mm.common.ex.ServiceException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    UserRepository repository;

    /**用户列表展示*/
    @Override
    public List<UserStandardVO> userList() {
        return repository.userList();
    }

    /**禁用账户*/
    @Override
    public void disabledUser(UserParam userParam) {
        userParam.setEnable(1);
        int i = repository.updateUser(userParam);
        if (i!=1){
            throw new ServiceException(ServiceCode.ERROR_UPDATE,"禁用失败，请稍后再试");
        }
    }

    @Override
    public void updateUser(UserParam userParam) {
        int i = repository.updateUser(userParam);
        if (i!=1){
            throw new ServiceException(ServiceCode.ERROR_UPDATE,"修改失败，请稍后再试");
        }
    }
}
